(function () {
    var win=new Win();
    win.mst("bd1px solid #999;bg#eee;w600;h400;l"+(body.width()/2-300)+";t"+(body.height()/2-200));
    //顶部状态栏 名字 关闭按钮
    (function () {
        var status=tag.div().mst("w100%;h30;bg#fff").attr("class","asWindow");
        win.append(status);

        //名字
        var name=tag.span().html("新用户注册").mst("fl;mt4;ml6");
        status.append(name);

        //关闭按钮
        var close=tag.canvas().attr({
            "width":"30",
            "height":"30"
        }).mst("bg#fff;fr;cup;tr300")
            .hover
            (
                function () {
                    $(this).mst("bg#f00");
                    drawClose(true);
                },
                function () {
                    $(this).mst("bg#fff");
                    drawClose(false);
                })
            .click
            (
                function () {
                    win.remove();
                }
            );
        var o=close[0].getContext("2d");
        function drawClose(isHover) {
            o.clearRect(0,0,30,30);
            o.beginPath();
            o.moveTo(8,8);
            o.lineTo(22,22);
            o.moveTo(8,22);
            o.lineTo(22,8);
            isHover?o.strokeStyle="#fff":o.strokeStyle="#333";
            o.stroke();
        }
        drawClose(false);
        status.append(close);

    })();
    //表单
    (function () {
        var box=tag.div().mst("w280;bg#fff;m0a;mt120");
        win.append(box);

        //密码 验证码
        var p,vc;

        //
        var iBox=tag.div().mst("w100%;bd1px solid #999");
        box.append(iBox);

        //
        function inputMode(title,type) {
            var div=tag.div().mst("w100%;bg#fff;h36");
            var ipt=tag.input(type,"").mst("w180;h36;bgnone").css({
                "border":"none",
                "outline":"none"
            });
            div.append
            (
                $("<span>"+title+"</span>").mst("lh36;w90;ml10"),
                ipt
            );
            div.ipt=ipt;
            return div;
        }
        function hr() {
            return tag.div().mst("w100%;h1;bg#999;mt1")
        }
        var pw=inputMode("输入密码：","password");
        var rpw=inputMode("确认密码：","password");
        var vci=inputMode("验证码：","text");
        var pic=tag.canvas().mst("w100%;h40;bg#eee");
        (function () {
            pic.attr({
                "width":pic.width(),
                "height":pic.height()
            });
            var c=pic[0];
            var o=c.getContext("2d");
            function draw(num) {
                o.clearRect(0,0,c.width,c.height);
                o.beginPath();

                for(var i=0;i<num.length;i++){
                    var t=num.substr(i,1);
                    var r=Math.random()*255;
                    var g=Math.random()*255;
                    var b=Math.random()*255;
                    o.font=(20+Math.floor(Math.random()*10))+"px arial";
                    o.fillStyle="rgb("+r+","+g+","+b+")";
                    if(Math.random()>0.5){
                        t=t.toLowerCase();
                    }
                    o.fillText(t,25+i*13,c.height-Math.random()*20);
                }
                for(var j=0;j<3;j++){
                    o.moveTo(0,Math.random()*c.height);
                    o.lineTo(c.width,Math.random()*c.height)
                }
                for(var k=0;k<5;k++){
                    o.moveTo(Math.random()*c.width,0);
                    o.lineTo(Math.random()*c.width,c.height)
                }
                o.lineWidth=2;
                o.strokeStyle="rgba(235,235,235,0.8)";
                o.stroke();

            }
            function getNum() {
                draw("a4A0");
            }getNum();
            pic.click(getNum);
        })();
        var count=tag.input("button","获取账户").mst("w100%;h40");
        iBox.append(pw,hr(),rpw,hr(),pic,hr(),vci,hr(),count);
        pw.ipt.attr("placeholder","6到16位字符");
        rpw.ipt.attr("placeholder","6到16位字符");
        count.click(function () {
            p=pw.ipt.val();
            var rp=rpw.ipt.val();
            vc=vci.ipt.val().toUpperCase();
            if(p===""){
                alert("请输入密码");
                return;
            }
            if(rp===""){
                alert("请输入确认密码");
                return;
            }
            if(vc===""){
                alert("请输入验证码");
                return;
            }
            if(p!==rp){
                alert("两次密码不一致，请重新输入");
                return;
            }


            myAjax("post","register.do","p="+p+"&vc="+vc,function (x) {
                alert(x)
            })
        });

    })();
})();